package dongchel.vrp.ais;

import java.util.ArrayList;
import java.util.List;

import dongchel.vrp.entity.MultiObjectiveObject;

public class Cell {
	private MultiObjectiveObject leftBoundary;
	private MultiObjectiveObject rightBoundary;
	
	private int size = 0;

	public Cell(){}
	
	public Cell(MultiObjectiveObject mo, MemorySpace ms){
		leftBoundary = new MultiObjectiveObject();
		rightBoundary = new MultiObjectiveObject();
		
		List lo = new ArrayList();
		List ro = new ArrayList();
		
		for(int i=0;i<mo.getObjectiveList().size();i++){
			double max = (Double)ms.getMaxSolutionSpace().getObjectiveList().get(i);
			double min = (Double)ms.getMinSolutionSpace().getObjectiveList().get(i);
						
			double currentD = (Double)mo.getObjectiveList().get(i);
			
			double step = (max-min)/ms.getCellNumer();
			lo.add(Math.ceil((currentD-min)/step-1));
			ro.add(Math.ceil((currentD-min)/step));
		}
		leftBoundary.setObjectiveList(lo);
		rightBoundary.setObjectiveList(ro);
		size++;
	}
	
	public MultiObjectiveObject getLeftBoundary() {
		return leftBoundary;
	}

	public void setLeftBoundary(MultiObjectiveObject leftBoundary) {
		this.leftBoundary = leftBoundary;
	}

	public MultiObjectiveObject getRightBoundary() {
		return rightBoundary;
	}

	public void setRightBoundary(MultiObjectiveObject rightBoundary) {
		this.rightBoundary = rightBoundary;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
	
	public void addSize(){
		this.size++;
	}
	
	public boolean checkIsContained(MultiObjectiveObject mo){
		for(int i=0;i<mo.getObjectiveList().size();i++){
			double currentD = (Double)mo.getObjectiveList().get(i);
			double leftD = (Double)leftBoundary.getObjectiveList().get(i);
			double rightD = (Double)rightBoundary.getObjectiveList().get(i);
			if(currentD < leftD || currentD > rightD){				
				return false;
			}
		}
		return true;
	}
}
